﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.IO.Compression;
using Ionic.Zip;

namespace LogsDownload.Models
{
    public class LogFiles
    {

        List<EventLog> listOfLogs=new List<EventLog>();
        public LogFiles()
        {           
            EventLog[] eventLogsArray = EventLog.GetEventLogs();            
            for (int i = 0; i < eventLogsArray.Length; i++)
            {
                listOfLogs.Add(eventLogsArray[i]);
            }
        }

        public List<EventLog> getLogs()
        {
            return listOfLogs;
        }

        public int getCount()
        {
            return listOfLogs.Count;
        }

        public static String[]  getPathOfZipFile()
        {

            //string partpath = String.Concat("C:/new"); //C:/ is just an example of pysical path to file
            //string file_path = String.Concat(partpath, ".evtx"); //got full path with concrete logfile name
            //string file_type = "application/octet-stream"; //type of evt file
            //string file_name = String.Concat(id, ".evtx"); //give the saving file name of downloading logfile
            //return File(file_path, file_type, file_name); //download file
        
            ZipFile zip = new ZipFile();
            string pathOfFiles = @"~\tmp\";
            string nameOfFiles = "2.txt";
            //zip.CompressionLevel = compressionLevel;
            ZipEntry ze = zip.AddFile(String.Concat(pathOfFiles, nameOfFiles));
            nameOfFiles = "1.txt";
            ze = zip.AddFile(String.Concat(pathOfFiles, nameOfFiles));
            nameOfFiles = "3.txt";
            ze = zip.AddFile(String.Concat(pathOfFiles, nameOfFiles));
            //zip.Save( @"C:\new\zipfile1.zip");

            string[] info = new string[3];
            info[0] = @"~\tmp\";
            info[1] = "zipfile1.zip";
            zip.Save(String.Concat(info[0], info[1] ));



            //string str="C:\new\lolzf.zip";
            //ZipFile;
            //ZipFile.CreateFromDirectory(@"C:\new", @"C:\new\zf.zip");

            return info ;
        }

    }
}